# pip install mitmproxy
# mitmproxy --version
# mitmdump -s httpProxy.py -p 9000


TARGET_URL = 'https://g.alicdn.com/secdev/sufei_data/3.9.9/index.js'
INJECT_TEXT = '''

if (!navigator.webdriver) {
    Object.defineProperties(navigator,{webdriver:{get:() => false}});
};
console.log("navigator.webdriver:" + navigator.webdriver)

'''
# "$cdc_asdjflasutopfhvcZLmcfl_"in u || f.webdriver
def response(flow):
    
    url = flow.request.url
    text = flow.response.text
    if ".js" in url and 'function' in text:
        a = 1
        text = 'var luoluqi = 1;' + text
        text = text.replace('$cdc_asdjflasutopfhvcZLmcfl_','$cdc_asdjflasutopfhvcZLmcfl_luoluqi')
        text = text.replace('webdriver','webdriver_luoluqi')

   
    if '/newlogin/account/check.do' in url:
        f = open('./log.txt','a',encoding='utf-8') 
        f.write(url + '\n')
        f.write('\n')
        f.write('\n')
        f.write(text + '\n')
        f.write('\n')
        f.write('\n')
        f.close()   
        text = """
            {"content":{"data":{"resultCode":100},"status":0,"success":true},"hasError":false, luoluqi:0}
         """

    flow.response.text = text

    